# 导包
import time
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.wait import WebDriverWait

# 打开浏览器
service = Service(r"D://Python314//chromedriver.exe")
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象

# 放大浏览器页面
driver.maximize_window()

# 2.输入访问地址（URL）
driver.get("http://121.43.169.97:8848/pageA.html")
# 实例化WebDriverWait，并调用until(method)方法
# 1). driver：浏览器驱动对象
# 2). timeout：超时的时长，单位：秒
# 3). poll_frequency：检测间隔时间，默认为0.5秒
# username = WebDriverWait(driver, 10, 1).until(lambda x: x.find_element_by_css_selector("#userA"))
# username.send_Keys("admin")
# username = WebDriverWait(driver,10,1).until(lambda  x: x.find_element(By.ID,"userA"))
# username.send_Keys("admin")


wait = WebDriverWait(driver, 10, 1)
username = wait.until(lambda x: x.find_element(By.CSS_SELECTOR,"userA"))
# username = wait.until(lambda x: x.find_element_by_css_selector("userA"))
username.send_keys("admin")


time.sleep(3)
driver.quit()